<?php
	session_start();
	//include("config.inc.php");
	include("dbconnect.inc.php");
	//include("header.inc.php");
	
	function substrgb($in,$num){
		$pos=0;
		$out="";
		while($c=substr($in,$pos,1)){
			if($c=="\n") break;
			if(ord($c)>128){
				$out.=$c;
				$pos++;
				$c=substr($in,$pos,1);
				$out.=$c;
			}else{
				$out.=$c;
			}
			$pos++;
			if($pos>=$num) break;
		}
		if($out!=$in) $out = $out . "...";
		return $out;
	}
?>
<table width="778" border="0" cellpadding="0" cellspacing="6" class="border">
<tr> 
<?php 

	//设置一个循环次数的标识
	$idx=1;
	//循环从数据库中检索到的栏目信息
	foreach($categorys as $id=>$category_name) {
?>
<td valign="top" width="263" class="listcontent"> 
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr><td class="listTitle"> 
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr><td><strong>
	<?php echo $category_name; ?></strong></td>
	<td align=right><a href="list.php?category=<?php echo $id; ?>">更多内容</a></td>
	</tr>
	</table>
</td></tr>
<tr> 
<td valign="top" class="list"> 
	<table cellspacing=0 cellpadding=2 width="100%" border=0>
<?php
	//根据当前循环中的category_id值(栏目编号)，检索 news 数据表，并取得最新的5条记录
	$sql = "select news_id,news_title from news where news_index={$id} order by pubtime desc limit 5";
	$res = mysql_query($sql);
	while($row = mysql_fetch_array($res)) {
		echo "sdf";
		//如果当前是管理模式，则设置编辑链接
		if($_SESSION["admin"]) {
			$edit_link = '<td width="50" align="right">
			[<a href="admin_editnews.php?id='.$row['id'].'">编辑</a>]</td>';
		}
?>
		<tr><td>
	<a href="display.php?id=<?php echo $row['id']; ?>" ><?php echo substrgb($row['title'],35); ?></a>
		</td>
	<?php echo $edit_link; ?>
		</tr><tr><td class="dotLine"></td></tr>
<?php
	}
?>
            </table></td></tr>
      </table>
    </td>
<?php
		//每循环3次，另起一个<TR>标签，在表格中增加一行。
		if(!($idx % 3)) echo "</tr><tr>";
		$idx++;
	}
?>
  </tr>
</table>

  
<?php include("footer.inc.php"); ?>